package com.example.manager.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.manager.entity.ScoreComposition;
import com.example.manager.repository.ScoreCompositionRepository;

@Service
@Transactional
public class ScoreCompositionServiceImpl implements ScoreCompositionService {
	
	@Autowired
	private ScoreCompositionRepository scoreComRepo;

	@Override
	public List<ScoreComposition> getAll() {
		return scoreComRepo.findAll();
	}

	@Override
	public List<ScoreComposition> getScoreCompositionByCourseTeachingId(Integer id) {
		
		return null;
	}

	@Override
	public String editScoreComposition(ScoreComposition scoreCom) {
		if(scoreCom.getPartName()==null||scoreCom.getPartName().length()==0||scoreCom.getScore()==null) {
			return "imcomplete info";
		}
		scoreComRepo.save(scoreCom);
		return "success";
	}

	@Override
	public String addScoreComposition(ScoreComposition scoreCom) {
		String partname = scoreCom.getPartName();
		
		if(partname==null||partname.length()==0||scoreCom.getScore()==null) {
			return "imcomplete info";
		}
		scoreComRepo.save(scoreCom);
		return "success";
		
	}

	@Override
	public String deleteScoreComposition(Integer id) {
		scoreComRepo.deleteById(id);
		return "success";
	}

}
